package vtc;

import java.util.Date;
import java.util.Calendar;
import java.util.concurrent.*;
import java.util.concurrent.*;
import java.io.File; 
import java.io.IOException;
import jxl.*;
import jxl.read.biff.*;

public class SynchronizationUnitExample extends SynchronizationUnit
{
	SynchronizationUnitExample(String id, VtcArrayBlockingQueue inQueues[], VtcArrayBlockingQueue outQueues[])
	{
		super(id, inQueues, outQueues);
	}
	
	// last event (oldest) of each queue
	// time tag of the newest event  
	public void synchronizationProcess() throws InterruptedException
	{
//		Date olddate = new Date();;
		
		for(int i = 0; i < inQueues_.length; i++)
		{
			VtcTimeTaggedEvent event =  inQueues_[i].take();
			eventsVector_[i] = event.getEvent();
			if(i==0)
			{
				timeTag_ = event.getTimeTag();
				//olddate = timeTag_;
			}
			else if(timeTag_.before(event.getTimeTag()))
			{	
				//olddate = timeTag_;
				timeTag_ = event.getTimeTag();
				 
			}
//			if(id_ == "p5")
//			{
//				System.out.print("queue " + i + "  old time tag:" + olddate + " out time tag: " + timeTag_+ "\n");
//				System.out.print("difference: " + (olddate.getTime()-timeTag_.getTime())/86400000 + "\n");
//			}
		}
	}
}